package com.diligreat.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.diligreat.cache.Cache;
import com.diligreat.domain.Lang;
import com.diligreat.service.LangService;
import com.diligreat.service.NavigationService;
import com.diligreat.service.StartUpService;
import com.diligreat.tools.MutipleLanguageResources;
import com.diligreat.util.CodeTransUtil;

public class OnStartupServlet extends HttpServlet{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 7524569638919218438L;

	public void init(ServletConfig config) throws ServletException {
		
		Cache.getCache();
		
		WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(config.getServletContext());
		NavigationService navigationService=(NavigationService)wac.getBean("navigationService");
		
		
		navigationService.getNavigationString();
		
		
		
		StartUpService startUpService=(StartUpService)wac.getBean("startUpService");
		Cache.getCache().setLang(startUpService.getSecStepLang());
		Cache.getCache().setArea(startUpService.getLangResource());
		
		//启动文字资源
		MutipleLanguageResources mlr=new MutipleLanguageResources();
		try {
			Cache.cache.setProps(mlr.readFiles());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void getLangInfo(WebApplicationContext wac){
		LangService langService = (LangService) wac.getBean("langService");
		List<Lang> list = langService.getLangSecStepGroup();
		for (Lang lang : list) {
			
			CodeTransUtil.langInfo.put(String.valueOf(lang.getId()), lang.getName());
		}
	}

}
